package com.e5.training.action;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.e5.training.domain.User;
import com.e5.training.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class UserListAction extends ActionSupport implements ModelDriven<Object>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private List<User> userlist = new ArrayList<User>();
	
	@Autowired
	private UserService userService;
	
	
	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		String flag = null;
		try {
			userlist = userService.listAllUser();
			if(userlist != null)
				flag = "success";
			else
				flag = "failure";
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	
		return flag;
	}


	/**
	 * @return the userlist
	 */
	public List<User> getUserlist() {
		return userlist;
	}


	/**
	 * @param userlist the userlist to set
	 */
	public void setUserlist(List<User> userlist) {
		this.userlist = userlist;
	}


	@Override
	public Object getModel() {
		// TODO Auto-generated method stub
		return userlist;
	}

}
